<template>
  <div class="tab-container">
    <el-tabs v-model="activeName" style="margin-top:15px;" type="border-card">
      <el-tab-pane v-for="item in tabMapOptions" :key="item.key" :label="item.label" :name="item.key">
        <keep-alive>
          <tab-pane v-if="activeName === item.key" :type="item.key" />
        </keep-alive>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import TabPane from './components/TabPane'

export default {
  name: 'BoxRecord',
  components: { TabPane },
  data() {
    return {
      tabMapOptions: [
        { label: '标签检测', key: '1' },
        { label: '喷码检测', key: '2' },
        { label: '箱体识别', key: '3' },
        { label: '外观检测', key: '4' }
      ],
      activeName: '1'
    }
  },
  watch: {
    activeName(val) {
      this.$router.push(`${this.$route.path}?tab=${val}`)
    }
  },
  created() {
    // init the default selected tab
    const tab = this.$route.query.tab
    if (tab) {
      this.activeName = tab
    }
  }
}
</script>

<style scoped>
.tab-container {
  margin: 20px;
}
</style>
